<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" href="../codebase/default.css" type="text/css" media="screen" title="no title" charset="utf-8"><title>
    dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu    [DHX documentation]
  </title></head>

<body>
<div class="dokuwiki">
  
  <div class="stylehead">

    <div class="header">
    <a class="logo" href="http://dhtmlx.com" title="DHTMLX Home Page"></a>
    <span class="tittle-dhtmlx">DHTMLX Docs & Samples Explorer</span>

    <div class="search-field">
        <form action="/dhtmlx/docs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>    </div>
        <div class="buttons">
                <a class="doc"></a>
                <a title="DHTMLX Samples homepage" href="../samples.html" class="sample"/></a>
        </div>
     <!-- <div class="pagename">
        [[<a href="#"  title="Backlinks">dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu</a>]]
      </div>
      <div class="logo">
        <a href="/dhtmlx/docs/doku.php"  name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[H]">DHX documentation</a>      </div>

      <div class="clearer"></div>-->
        
    </div>

    
<!--   <div class="bar" id="bar__top">
      <div class="bar-left" id="bar__topleft">
        <form class="button btn_edit" method="post" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="edit" /><input type="hidden" name="rev" value="" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Edit this page" class="button" accesskey="e" title="Edit this page [E]" /></div></form>        <form class="button btn_revs" method="get" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>      </div>

      <div class="bar-right" id="bar__topright">
        <form class="button btn_recent" method="get" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="recent" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Recent changes" class="button" accesskey="r" title="Recent changes [R]" /></div></form>        <form action="/dhtmlx/docs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>&nbsp;
      </div>

      <div class="clearer"></div>
    </div> -->

<!--        <div class="breadcrumbs">
      <span class="bchead">Trace:</span> <span class="bcsep">&raquo;</span> <span class="curid"><a href="/dhtmlx/docs/doku.php?id=dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu"  class="breadcrumbs" title="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu">api_method_dhtmlxganttchart_setcontextmenu</a></span>    </div>
    -->

    
  </div>
  
  
  <div class="page">
    <!-- wikipage start -->
    


<h3><a name="setcontextmenu_menu" id="setcontextmenu_menu">setContextMenu(menu)</a></h3>
<div class="level3">
<ul>
<li class="level1"><div class="li"> menu - {<a href="http://docs.dhtmlx.com/doku.php?id=dhtmlxmenu:toc" class="wikilink1" title="dhtmlxmenu:toc">dhtmlXMenuObject</a>}</div>
</li>
</ul>

<p>

adds custom context menu of type <a href="http://docs.dhtmlx.com/doku.php?id=dhtmlxmenu:toc" class="wikilink1" title="dhtmlxmenu:toc">dhtmlXMenuObject</a>. Use “onBeforeContextMenu” event to customize menu for a particular tree item.
</p>
<pre class="code javascript">    <span class="sy0">&lt;</span>link rel<span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> href<span class="sy0">=</span><span class="st0">&quot;../dhtmlxMenu/codebase/skins/dhtmlxmenu_dhx_skyblue.css&quot;</span><span class="sy0">&gt;</span>
    <span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> language<span class="sy0">=</span><span class="st0">&quot;JavaScript&quot;</span> src<span class="sy0">=</span><span class="st0">&quot;../dhtmlxMenu/codebase/dhtmlxmenu.js&quot;</span><span class="sy0">&gt;&lt;/</span>script<span class="sy0">&gt;</span>
    <span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span> language<span class="sy0">=</span><span class="st0">&quot;JavaScript&quot;</span> src<span class="sy0">=</span><span class="st0">&quot;../dhtmlxMenu/codebase/ext/dhtmlxmenu_ext.js&quot;</span><span class="sy0">&gt;&lt;/</span>script<span class="sy0">&gt;</span></pre><pre class="code javascript">    <span class="kw2">var</span> menu <span class="sy0">=</span> <span class="kw2">new</span> dhtmlXMenuObject<span class="br0">&#40;</span><span class="br0">&#41;</span>;
    menu.<span class="me1">setIconsPath</span><span class="br0">&#40;</span><span class="st0">&quot;../dhtmlxMenu/codebase/imgs/dhtmlxmenu_dhx_skyblue&quot;</span><span class="br0">&#41;</span>;
    menu.<span class="me1">renderAsContextMenu</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;
    menu.<span class="me1">loadXMLString</span><span class="br0">&#40;</span><span class="st0">'&lt;menu&gt;&lt;item id=&quot;m1&quot; text=&quot;Item name placeholder&quot;/&gt;&lt;item id=&quot;m2&quot; text=&quot;Get info&quot;/&gt;&lt;/menu&gt;'</span><span class="br0">&#41;</span>;
    menu.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;onClick&quot;</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>id<span class="br0">&#41;</span><span class="br0">&#123;</span>
        <span class="kw2">var</span> obj <span class="sy0">=</span> menu.<span class="me1">getUserData</span><span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="sy0">,</span><span class="st0">&quot;obj&quot;</span><span class="br0">&#41;</span>;
        <span class="kw1">if</span> <span class="br0">&#40;</span>obj<span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw2">var</span> o <span class="sy0">=</span> obj.<span class="me1">o</span>;
            <span class="kw1">if</span> <span class="br0">&#40;</span>obj.<span class="me1">type</span> <span class="sy0">==</span> <span class="st0">&quot;p&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Project, id=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getId</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;, name=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;, start date=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getStartDate</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span>
                        <span class="st0">&quot;, duration=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getDuration</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;hours, percent complete=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getPercentCompleted</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;%&quot;</span><span class="br0">&#41;</span>;
            <span class="br0">&#125;</span> <span class="kw1">else</span>
            <span class="kw1">if</span> <span class="br0">&#40;</span>obj.<span class="me1">type</span> <span class="sy0">==</span> <span class="st0">&quot;t&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Task, id=&quot;</span> <span class="sy0">+</span> obj.<span class="me1">o</span>.<span class="me1">getId</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;, name=&quot;</span> <span class="sy0">+</span> obj.<span class="me1">o</span>.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;, EST=&quot;</span> <span class="sy0">+</span> obj.<span class="me1">o</span>.<span class="me1">getEST</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span>
                        <span class="st0">&quot;, duration=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getDuration</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;hours, percent complete=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getPercentCompleted</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;%&quot;</span> <span class="sy0">+</span>
                        <span class="st0">&quot;, parentTaskId=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getParentTaskId</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;, pred.taskId=&quot;</span> <span class="sy0">+</span> o.<span class="me1">getPredecessorTaskId</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span>;
    ganttChartControl.<span class="me1">setContextMenu</span><span class="br0">&#40;</span>menu<span class="br0">&#41;</span>;
    ganttChartControl.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;onBeforeContextMenu&quot;</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span>menu<span class="sy0">,</span>obj<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
        <span class="co1">// A sample of disabling menu for some particular tree item</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>obj.<span class="me1">getId</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">==</span><span class="nu0">15</span><span class="br0">&#41;</span> <span class="kw1">return</span> <span class="kw2">false</span>;
&nbsp;
        <span class="kw1">if</span> <span class="br0">&#40;</span>obj.<span class="me1">isProject</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">// Project menu</span>
            menu.<span class="me1">setItemText</span><span class="br0">&#40;</span><span class="st0">&quot;m1&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Project: &quot;</span> <span class="sy0">+</span> obj.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
            menu.<span class="me1">setUserData</span><span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="sy0">,</span><span class="st0">&quot;obj&quot;</span><span class="sy0">,</span><span class="br0">&#123;</span>type<span class="sy0">:</span><span class="st0">&quot;p&quot;</span><span class="sy0">,</span>o<span class="sy0">:</span>obj<span class="br0">&#125;</span><span class="br0">&#41;</span>;
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="kw1">if</span> <span class="br0">&#40;</span>obj.<span class="me1">isTask</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="co1">// Task menu</span>
            menu.<span class="me1">setItemText</span><span class="br0">&#40;</span><span class="st0">&quot;m1&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Task: &quot;</span> <span class="sy0">+</span> obj.<span class="me1">getName</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
            menu.<span class="me1">setUserData</span><span class="br0">&#40;</span><span class="st0">&quot;&quot;</span><span class="sy0">,</span><span class="st0">&quot;obj&quot;</span><span class="sy0">,</span><span class="br0">&#123;</span>type<span class="sy0">:</span><span class="st0">&quot;t&quot;</span><span class="sy0">,</span>o<span class="sy0">:</span>obj<span class="br0">&#125;</span><span class="br0">&#41;</span>;
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span>;
&nbsp;
    ganttChartControl.<span class="me1">create</span><span class="br0">&#40;</span><span class="st0">&quot;div15&quot;</span><span class="br0">&#41;</span>;</pre>
</div>

    <!-- wikipage stop -->
  </div>

  <div class="clearer">&nbsp;</div>

  
  <div class="stylefoot">

    <div class="meta">
      <div class="user">
              </div>
     <!-- <div class="doc">
        dhtmlxgantt/api_method_dhtmlxganttchart_setcontextmenu.txt &middot; Last modified: 2010/08/26 13:31 (external edit)      </div>
    </div>-->

   
    <!--<div class="bar" id="bar__bottom">-->
      <!--<div class="bar-left" id="bar__bottomleft">-->
        <!--<form class="button btn_edit" method="post" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="edit" /><input type="hidden" name="rev" value="" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Edit this page" class="button" accesskey="e" title="Edit this page [E]" /></div></form>-->
        <!--<form class="button btn_revs" method="get" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>-->
      <!--</div>-->
      <!--<div class="bar-right" id="bar__bottomright">-->
        <!---->
        <!---->
        <!---->
        <!---->
        <!---->
        <!--<form class="button btn_index" method="get" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="index" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Index" class="button" accesskey="x" title="Index [X]" /></div></form>-->
        <!--<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="Back to top" onclick="window.scrollTo(0, 0)" title="Back to top" /></a>&nbsp;-->
      <!--</div>-->
      <!--<div class="clearer"></div>-->
    <!--</div>-->

  </div>

  

</div>

<div class="footerinc">


</div>

<div class="no"><img src="/dhtmlx/docs/lib/exe/indexer.php?id=dhtmlxgantt%3Aapi_method_dhtmlxganttchart_setcontextmenu&amp;1282819185" width="1" height="1" alt=""  /></div>
     <div class="footer">
        <div class="footer-logo"></div>
        <div class="copyright">Copyright © 1998-2009 DHTMLX LTD.<br />All rights reserved.</div>
        <form class="button btn_edit" method="post" action="/dhtmlx/docs/doku.php"><div class="no"><input type="hidden" name="do" value="edit" /><input type="hidden" name="rev" value="" /><input type="hidden" name="id" value="dhtmlxgantt:api_method_dhtmlxganttchart_setcontextmenu" /><input type="submit" value="Edit this page" class="button" accesskey="e" title="Edit this page [E]" /></div></form>    	    </div>
</body>
</html>
